package factory.demo1.controller;

import factory.demo1.FreeGoodsFactory;
import factory.demo1.entity.AwardInfo;
import factory.demo1.entity.ResponseResult;
import factory.demo1.service.IFreeGoods;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 1
 * @version 1.0
 * @description: TODO
 * @date 2024-08-28 13:50
 */
public class DeliverController {
    /**
     * 发放奖品
     */
    public static ResponseResult awardToUser(AwardInfo awardInfo){
        try {
            IFreeGoods freeGoods = FreeGoodsFactory.getInstance(awardInfo.getAwardType());
            ResponseResult responseResult = freeGoods.sendFreeGoods(awardInfo);
            return responseResult;
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(201,"奖品发放失败!");
        }
    }

    public static void main(String[] args) {
        //发放折扣券
        test1();
        //发优酷会员
        test2();
        //发放小礼品
        test3();
    }

    public static void test1(){
        //发放折扣券
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardNumber("101010");
        awardInfo.setAwardType(1);
        ResponseResult responseResult = awardToUser(awardInfo);
        System.out.println(responseResult);
    }
    public static void test2(){
        //发优酷会员
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardNumber("101010");
        awardInfo.setAwardType(2);
        Map<String, String> map = new HashMap<String, String>();
        map.put("phone", "123456789");
        awardInfo.setExtMap(map);
        ResponseResult responseResult = awardToUser(awardInfo);
        System.out.println(responseResult);
    }
    public static void test3(){
        //发放小礼品
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardNumber("101010");
        awardInfo.setAwardType(3);
        ResponseResult responseResult = awardToUser(awardInfo);
        System.out.println(responseResult);
    }


}
